package DecChallenges;

//https://leetcode.com/problems/buy-two-chocolates/description/?envType=daily-question&envId=2023-12-17
//很多阅读理解题
public class Day11_P2706 {
    public static void main(String[] args) {

    }

    public int buyChoco(int[] prices, int money) {
        int min = 101, minIndex = -1;
        for(int i = 0; i < prices.length; i++) {
            if(prices[i] < min) {
                min = prices[i];
                minIndex = i;
            }
        }

        int subMin = 101, subMinIndex = -1;
        for(int i = 0; i < prices.length; i++) {
            if(prices[i] < subMin && i != minIndex) {
                subMin = prices[i];
                subMinIndex = i;
            }
        }

        int two = min + subMin;
        return two > money ? money : money - two;
    }
}
